<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>kernel.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>K&nbsp;</span>=&nbsp;<span class=defun_name>kernel</span>(<span class=defun_in>varargin</span>)<br>
<span class=h1>%&nbsp;KERNEL&nbsp;Evaluates&nbsp;kernel&nbsp;function.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;=&nbsp;kernel(X,ker,arg)</span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;=&nbsp;kernel(X1,X2,ker,arg)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;=&nbsp;kernel(&nbsp;X,&nbsp;ker,&nbsp;arg&nbsp;)&nbsp;returns&nbsp;kernel&nbsp;matrix&nbsp;K&nbsp;[n&nbsp;x&nbsp;n]&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;K(i,j)&nbsp;=&nbsp;k(X(:,i),X(:,j))&nbsp;&nbsp;for&nbsp;all&nbsp;i=1..n,&nbsp;j=1..n,</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;where&nbsp;k:&nbsp;a&nbsp;x&nbsp;b&nbsp;-&gt;&nbsp;R&nbsp;is&nbsp;a&nbsp;kernel&nbsp;function&nbsp;given&nbsp;by&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;identifier&nbsp;ker&nbsp;and&nbsp;argument&nbsp;arg:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;Identifier&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Definition</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;'linear'&nbsp;&nbsp;...&nbsp;linear&nbsp;kernel&nbsp;&nbsp;k(a,b)&nbsp;=&nbsp;a'*b</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;'poly'&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;polynomial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k(a,b)&nbsp;=&nbsp;(a'*b+arg[2])^arg[1]</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;'rbf'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;RBF&nbsp;(Gaussian)&nbsp;k(a,b)&nbsp;=&nbsp;exp(-0.5*||a-b||^2/arg[1]^2)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;'sigmoid'&nbsp;...&nbsp;Sigmoidal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k(a,b)&nbsp;=&nbsp;tanh(arg[1]*(a'*b)+arg[2])</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;=&nbsp;kernel(&nbsp;X1,&nbsp;X2,&nbsp;ker,&nbsp;arg&nbsp;)&nbsp;returns&nbsp;kernel&nbsp;matrix&nbsp;K&nbsp;[n1&nbsp;x&nbsp;n2]</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;K(i,j)&nbsp;=&nbsp;k(X1(:,i),X2(:,j))&nbsp;&nbsp;for&nbsp;all&nbsp;i=1..n1,&nbsp;j=1..n2,</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;X&nbsp;[dim&nbsp;x&nbsp;n]&nbsp;Single&nbsp;matrix&nbsp;of&nbsp;input&nbsp;vectors.</span><br>
<span class=help>%&nbsp;&nbsp;X1&nbsp;[dim&nbsp;x&nbsp;n1],&nbsp;X2&nbsp;[dim&nbsp;x&nbsp;n2]&nbsp;Pair&nbsp;of&nbsp;input&nbsp;matrices.</span><br>
<span class=help>%&nbsp;&nbsp;ker&nbsp;[string]&nbsp;Kernel&nbsp;identifier.</span><br>
<span class=help>%&nbsp;&nbsp;arg&nbsp;[1&nbsp;x&nbsp;&nbsp;narg]&nbsp;Kernel&nbsp;argument.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;[n1&nbsp;x&nbsp;n1]&nbsp;or&nbsp;K&nbsp;[n1&nbsp;x&nbsp;n2]&nbsp;Kernel&nbsp;matrix.</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;X&nbsp;=&nbsp;rand(2,50);</span><br>
<span class=help>%&nbsp;&nbsp;K&nbsp;=&nbsp;kernel(&nbsp;X,&nbsp;'rbf',&nbsp;1);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;pcolor(&nbsp;K&nbsp;);</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also:</span><br>
<span class=help>%&nbsp;&nbsp;DIAGKER,&nbsp;KERNELPROJ.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;19-sep-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;5-may-2004,&nbsp;VF</span><br>
<br>
<hr>
<span class=comment>%&nbsp;MEX-File&nbsp;function.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br>
</code>
